package logic

import (
	"context"
	"fmt"
	"house_srv/model/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *house.AddRequest) (*house.AddResponse, error) {
	// todo: add your logic here and delete this line
	houses := mysql.House{
		Address: in.Address,
		Size:    in.Size,
		Price:   float64(in.Price),
		Name:    in.Name,
		Image:   in.Image,
	}
	err := mysql.DB.Debug().Create(&houses).Error
	if err != nil {
		return nil, fmt.Errorf("添加失败")
	}
	return &house.AddResponse{
		Id: int64(houses.ID),
	}, nil
}
